home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5099 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  49 lines

  1. Path: news.lpr.carel.fi!usenet
  2. From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Where Can I Find Standard C Library S
  5. Date: Thu, 08 Feb 1996 14:04:41 +0200
  6. Organization: Carelcomp Forest
  7. Message-ID: <3119E6D9.60FD@cmt.lpr.mail.carel.fi>
  8. References: <4fb8mf$ouo@spanky.pls.ov.com> <4fb90l$ouo@spanky.pls.ov.com>
  9. NNTP-Posting-Host: renoir.cclahti.carel.fi
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b6a (WinNT; I)
  14.  
  15. Fletcher.Glenn@ov.com wrote:
  16. > Whoops! for strcpy:
  17. > char *strcpy(char *destination, char *source)
  18. > {
  19. >     char *retval;
  20. >     retval = destination;
  21. >     while((*destination++ = *source++) != '\0');
  22. >     return(retval);
  23. > }
  24. >                         Fletcher.Glenn@ov.com
  25.  
  26. ... And you wonder why printf("%s\n", strcpy(tmp, "thingyam")); may not give correct 
  27. results using your strcpy version... Try this for size:
  28.  
  29.     char *strcpy(char *destination, char *source)
  30.     {
  31.         char *retval = destination;
  32.  
  33.         do
  34.             *destination = *source++;
  35.         while (*destination++ != '\0');
  36.         return retval;
  37.     }
  38.  
  39. This will also copy the nul-terminator. :)
  40.  
  41. Later,
  42.  AriL
  43. -- 
  44. All my opinions are mine and mine alone.
  45.